<template>
  <div class="">
    <div class="filter-container">
      <el-input v-model="listQuery.name" clearable class="filter-item" style="width: 200px;" placeholder="搜索管理员账号"/>
      <el-select v-model="listQuery.isLogin" style="width: 200px" class="filter-item" placeholder="请选择日志类型">
        <el-option :label="'全部类型'" :value="''" />
        <el-option v-for="type in logTypes" :key="type.id" :label="type.name" :value="type.id"/>
      </el-select>
      <el-button v-permission="['login:list']" class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">查找</el-button>
    </div>

    <el-table v-loading="listLoading" :data="list" size="small" element-loading-text="正在查询中..." border fit highlight-current-row>
      <el-table-column align="center" label="ID" width="100" prop="id" />
      <el-table-column align="center" label="管理员" width="100" prop="userName" />
      <el-table-column align="center" label="操作" prop="isLogin" width="100">
        <template slot-scope="scope">{{ scope.row.login?'登录':'登出' }}</template>
      </el-table-column>
      <el-table-column align="center" label="IP" prop="ip" width="100"/>
      <el-table-column align="left" label="地址" width="150">
        <template slot-scope="scope">
          {{ scope.row.country }} {{ scope.row.city }}
        </template>
      </el-table-column>
      <el-table-column align="center" width="200" label="操作时间" prop="createDate"/>
      <el-table-column align="left" label="用户代理" prop="userAgent"/>
    </el-table>
    <pagination v-permission="['login:list']" v-show="total>0" :total="total" :page.sync="listQuery.pageNo" :limit.sync="listQuery.pageSize" @pagination="getList"/>
  </div>
</template>

<script>
import { LogsService } from '@/api/SystemService'
import Pagination from '@/components/Pagination'

export default {
  name: 'AdminLoginLog',
  components: { Pagination },
  data() {
    return {
      activeName: 'op_logs',
      list: null, total: 0, listLoading: true, logTypes: [{ id: true, name: '登录日志' }, { id: false, name: '登出日志' }],
      listQuery: { pageNo: 1, pageSize: 20, name: undefined, isLogin: undefined }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      LogsService.listLoginLog(this.listQuery).then(response => {
        this.list = response.data
        this.total = response.totalCount
        this.listLoading = false
      })
    },
    handleFilter() {
      this.listQuery.pageNo = 1
      this.getList()
    }
  }
}
</script>

<style>
</style>
